<template>
  <div>
    <TopBar :title="cate_name"></TopBar>
    <div class="books">
      <Book2 v-for="item in book_list" :key="item" :title="item.g_name" :img_path="item.img" :author="item.price"
             :intro="item.burdening" :id="item.id"></Book2>
    </div>
  </div>
</template>

<script>
import TopBar from "@/components/TopBar";
import Book2 from "@/components/Book2";

export default {
  name: "CateListView.vue",
  components: {
    TopBar,
    Book2,
  },
  data() {
    return {
      id: this.$route.query.id,
      book_list: [],
      cate_name: "",
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      console.log(this.id)
      if (this.id == 'hot') {
        this.$axios.get("/book/hot/50").then(res => {
          if (res.data.code == 200) {
            this.book_list = res.data.data.list
            this.cate_name = "畅销书籍"
          }
        })
      } 
      else if (this.id == 'recomm') {
        this.$axios.get("/book/recomm/50").then(res => {
          if (res.data.code == 200) {
            this.book_list = res.data.data.list
            this.cate_name = "今日推荐"
          }
        })
      } else if (this.id == "search") {
        let word = this.$route.query.word
        this.$axios.get("/book/search/" + word).then(res => {
          if (res.data.code == 200) {
            this.book_list = res.data.data
            this.cate_name = "搜索 - " + word
          }
        })
      }
      else {
        this.$axios.get('business/cate/' + this.id + "/").then(res => {
          if (res.data.code == 200) {
            console.log('>>>>>>>>>',res.data.data)
            this.book_list = res.data.data
            this.cate_name = res.data.c_name
          }
        })
      }
    }
  }
}
</script>

<style scoped>
.books {
  padding: 0 10px;
}
</style>